//--------------------------------------------------------------------------------------------------------------------- 
// <copyright file="SPScope.cs" company="Collaboris Ltd">
//   Copyright (c) Collaboris Ltd. All rights reserved.
// </copyright>
// <summary>
//   Defines the SPScope type.
// </summary>
//---------------------------------------------------------------------------------------------------------------------
namespace Collaboris.Saf
{
    using Microsoft.SharePoint;

    /// <summary>
    /// Defines the Scope for the calling context
    /// </summary>
    public enum SPScope
    {
        /// <summary>
        /// No Scope 
        /// </summary>
        None = 0,

        /// <summary>
        /// Operates at the SPWeb Scope
        /// </summary>
        Web = 10,
        
        /// <summary>
        /// Operates at the SPSite Scope
        /// </summary>
        Site = 20,
        
        /// <summary>
        /// Operates at the SPWebApplication Scope
        /// </summary>
        WebApplication = 30,
        
        /// <summary>
        /// Operates at the SPFarm Scope
        /// </summary>
        Farm = 40,        
    }

    /// <summary>
    /// Class providing <see cref="SPScope"/> related functionality.
    /// </summary>
    public class SPScopeConverter
    {
        /// <summary>
        /// Converts to feature scope from an <see cref="SPScope"/>.
        /// </summary>
        /// <param name="scope">The scope.</param>
        /// <returns></returns>
        public static SPFeatureScope ConvertToFeatureScope(SPScope scope)
        {
            switch (scope)
            {
                case SPScope.None:
                    return SPFeatureScope.ScopeInvalid;
                    
                case SPScope.Web:
                    return SPFeatureScope.Web;

                case SPScope.Site:
                    return SPFeatureScope.Site;

                case SPScope.WebApplication:
                    return SPFeatureScope.WebApplication;

                case SPScope.Farm:
                    return SPFeatureScope.Farm;

                default:
                    return SPFeatureScope.ScopeInvalid;

            }
        
        }

        /// <summary>
        /// Converts from feature scope to an <see cref="SPScope"/>
        /// </summary>
        /// <param name="featureScope">The feature scope.</param>
        /// <returns></returns>
        public static SPScope ConvertFromFeatureScope(SPFeatureScope featureScope)
        {

            switch (featureScope)
            {
                case SPFeatureScope.Farm:
                    return SPScope.Farm;
                    
                case SPFeatureScope.ScopeInvalid:
                    return SPScope.None;
                    
                case SPFeatureScope.Site:
                    return SPScope.Site;
                    
                case SPFeatureScope.Web:
                    return SPScope.Web;
                    
                case SPFeatureScope.WebApplication:
                    return SPScope.WebApplication;
                    
                default:
                    return SPScope.None;
                    
            }
        }
    }
}